FrameControl is used to draw frames around controls. Pass it: the name of the form, the name of the control, the offset, and the width of the frame. 5 is a good offset, 1 or 2 a good width.
[Code]
'Declares for FrameControl
Global Const HiColor = &HFFFFFF
Global Const LoColor = &H808080
Sub FrameControl (F As Form, C As Control, OffSet As Integer, Width As Integer)
GetSysDir returns the path of the Windows System directory
Pass it the name of the string you want SysPath assigned to.
[Code]
'Declares for GetSystemDir
Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Sub GetSystemDir (SystemPath$)
DIM Sys As String * 256
x = GetSystemDirectory(Sys, Len(Sys))
x = InStr(1, Sys, Chr$(0))
SystemPath$ = Left$(Sys, Instr(Sys,Chr$(0))-1)
End Sub
[Stop]
[3]
CenterForm centers the form passed to it horizontally and vertically on the screen.
[Code]
Sub CenterForm (F As Form)
F.Left = (Screen.Width - F.Width) / 2
F.Top = (Screen.Height - F.Height) / 2
End Sub
[Stop]
[4]
Loaded tells if an app of the passed classname is loaded
[Code]
'Declares for Loaded
Declare Function FindWindow Lib "user" (ByVal CName As Any, ByVal Caption As Any)
Function Loaded (ClassName$)
Loaded = FindWindow(ClassName$, 0&)
End Function
[Stop]
[5]
Wait "secs" bfore returning to call, allows vb to finish an executed command.
[Code]
Sub WaitSecs (secs)
Dim sTart!, Temp%
start! = Timer
While Timer < start! + secs +1
Temp% = DoEvents()
Wend
End Sub
[Stop]
[6]
RestoreApp restores the windows whose handle you pass to it.
[Code]
'Declares for RestoreApp
Declare Function IsIconic Lib "user" (ByVal hWnd As Any)
Sub RestoreApp (wHandle)
WM_SYSCOMMAND = &H112
SC_RESTORE = &HF120
If IsIconic(Instance) Then
T = PostMessage(Instance, WM_SYSCOMMAND, SC_RESTORE, 0)
WaitSecs 1
End If
End Sub
[Stop]
[7]
Tracks a popup menu.
Pass it the number (going from right to left) of the menu you wish to view, the X & Y coordinates at which it should pop up (as returned by a mousedown event), the form on which the mousedown event took place (and over which the menu should appear), and the form to which the menu belongs (which may or may not be the same as the previous form).
'2 tells it to use right mouse button, 1 the left button
r = TrackPopupMenu(hSubMenu%, 2, ix, iy, 0, MenuForm.hWnd, 0)
End Sub
[Stop]
[8]
MakeBeep beeps the PC's speaker a specified number of times
[Code]
Sub MakeBeep (Reps%)
For X=1 to Reps%
Beep
Next
End Sub
[Stop]
[9]
Extracts icons from a specified Exe file.
[Code]
'Declares for IconExtractor
Const GWW_HINSTANCE = (-6)
Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function ExtractIcon Lib "shell" (ByVal lpHandle As Integer, ByVal lpExe As String, ByVal lpiconindex As Integer) As Integer
Declare Function DrawIcon Lib "USER" (ByVal lpHandle As Integer, ByVal xcoord As Integer, ByVal ycoord As Integer, ByVal Hicon As Integer) As Integer
Sub IconExtractor (ExeFile$, F as Form, Pic as Picture)
Handle = F.hWnd
z = SCREEN.HEIGHT
Select Case z
Case 7000
X = 2: Y = 1
Case 7200
X = 3: Y = 0
Case 9000
X = 3: Y = 0
Case Is > 9000
X = 8: Y = 4
End Select
Static Looper
Looper = Looper + 1
Inst = GetWindowWord(Handle, GWW_HINSTANCE)
Hicon = ExtractIcon(Inst, ExeFile$, Looper - 1)
If Hicon = 0 Then
If Looper > 0 Then
Hicon = ExtractIcon(Inst, ExeFile$, 0)
Looper = 1
Else Beep: Exit Sub
End If
End If
F.Pic.CLS
Draw = DrawIcon(F.Pic.hDC, X, Y, Hicon)
End Sub
[Stop]
[10]
FormStayOnTop establishes the specified window as the topmost window no matter which window is active.
Pass it the handle of the window you want to make topmost (or for which you wish to end that condition) and a true/false flag to indicate whether it should be topmost.
[Code]
'Declares for FormStayOnTop
Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
Sub FormStayOnTop (Handle%, OnTop%)
Const Swp_Nosize = &H1
Const SWP_Nomove = &H2
Const Swp_NoActivate = &H10
Const Swp_ShowWindow = &H40
Const Hwnd_TopMost = -1
Const Hwnd_NoTopMost = -2
wFlags = SWP_Nomove Or Swp_Nosize Or Swp_ShowWindow Or Swp_NoActivate
Select Case OnTop%
Case True
PosFlag = Hwnd_TopMost
Case False
PosFlag = Hwnd_NoTopMost
End Select
SetWindowPos Handle%, PosFlag, 0, 0, 0, 0, wFlags
End Sub
[Stop]
[11]
Testlength can be used to test whether more than a specified number of characters has been entered into a textbox. If so, it deletes backwards from the insertion point until the text length is within the specified limit.
[Code]
'Declares for TestLength
Global Const MB_ICONEXCLAMATION = 48
Sub TestLength (C As Control, L As Integer)
Select Case Len(C.Text)
Case Is <= L
Exit Sub
Case Else
MsgBox "This field is limited to " + Str$(L) + " characters only! ", MB_ICONEXCLAMATION, "CopyFlow"
LeftText$ = Left$(C.Text, C.SelStart)
RightText$ = Mid$(C.Text, C.SelStart + 1)
LeftText$ = Left$(LeftText$, L - Len(RightText$))
C.Text = LeftText$ + RightText$
End Select
End Sub
[Stop]
[12]
Routine to locate the progenitor of a series of Windows
[Code]
'Declares for Find Parent
Declare Function GetParent Lib "User" (ByVal hWnd As Integer) As Integer
Function FindProgentor (WinHand As Integer) As Integer
Parent% = GetParent(WinHand%)
OldParent%=Parent%
'Get the parent of the parent if any
Do While Parent%
OldParent% = Parent%
Parent% = GetParent%(OldParent%)
' Debug.Print Parent%
Loop
Parent%=OldParent%
FindProgenitor = Parent%
End Function
[Stop]
[13]
The Exists%() function returns a value of TRUE if the specified file exists, or FALSE if it doesn't.
Function IsValidPath (DestPath$, ByVal DefaultDrive$) As Integer
'----------------------------
' Remove left and right spaces
'----------------------------
DestPath$ = RTrim$(LTrim$(DestPath$))
'-----------------------------
' Check Default Drive Parameter
'-----------------------------
If Right$(DefaultDrive$, 1) <> ":" Or Len(DefaultDrive$) <> 2 Then
MsgBox "Bad default drive parameter specified in IsValidPath Function. You passed, """ + DefaultDrive$ + """. Must be one drive letter and "":"". For example, ""C:"", ""D:""...", 64, "Setup Kit Error"
Checks if Filename is valid. Checks if there are any control char. Function is Flag controlled, means it can check Pathnames or Filenames depending on Flag. 1= Filename, 2=Pathname, Flag Type is Int byVal.
[Code]
'Declares for Filename is Valid?
R% = FNameIsValid (VFName$, StrFlag%)
'Function FNameIsValid (VFName$, ByVal StrFlag%) As Integer
'Dim KeyAscii%
'' ** START always positive YEAH !
' FNameIsValid = True
' ' ** Sting is empty quit now.
' If (VFName = "") Or (VFName = " ") Then
' FNameIsValid = False
' Exit Function
' End If
' ' ** Test Routines: check if ascii characters are OK.
' Select Case StrFlag%
' Case 1
' ' ---------> Check valid FILENAME !
' Select Case KeyAscii
' Case Is < Asc("!")
' FNameIsValid = False
' Case Is > Asc("z")
' FNameIsValid = False
' Case Is = Asc("┤")
' FNameIsValid = False
' Case Is = Asc(",")
' FNameIsValid = False
' Case Is = Asc(":")
' FNameIsValid = False
' Case Is = Asc("/")
' FNameIsValid = False
' Case Is = Asc("\")
' FNameIsValid = False
' End Select
' Case 2
' ' ---------> Check valid PATHNAME !
' Select Case KeyAscii
' Case Is < Asc("!")
' FNameIsValid = False
' Case Is > Asc("z")
' FNameIsValid = False
' Case Is = Asc("┤")
' FNameIsValid = False
' Case Is = Asc(",")
' FNameIsValid = False
' Case Is = Asc(":")
' FNameIsValid = False
' End Select
' Case 3
' ' ** RESERVED for later use **
' Case 4
' ' ** RESERVED **
' Case Is > 4
' ' ---------> Illegal Call !
' Exit Function
' Case 0
' ' ---------> Illegal Call, probably a bug ?
' Exit Function
' End Select
'End Function
[Stop]
[39]
Determine the Graphic Card by calculating the max screen resolution. Returns a number which refers to the graphic card type: 1=CGA, 2=EGA, 3=VGA, 4=HVGA, 5=SVGA....
[Code]
'Declares for Get Graphic Adapter
Card% = GetGraphicCard ()
'Function GetGraphicCard () As Integer
'Dim y%, X%
'' 1.) --> SWITCH TO TWIPS FIRST: 1 cm = 567 twips
''-> RESOLUTION: up to 1600x1280 -> END Graphic-Adapter Test
'End Function
[Stop]
[40]
Split full Filename into Filename, Pathname, Extension, Filename w/o Extens. The function is Flag driven, 1=Drivechar, 2=Pathname, 3=full Filename, 4=Extension, 5=Patterns/Wildcards, 6=pur Filename....